<template>
	<el-drawer title="任务处理对话框" v-model="visible" :size="600" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-main>
				<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="当前进度" prop="progress">
								<el-input-number v-model="this.progress" placeholder="当前进度" :min="1" :max="100" clearable></el-input-number>
								%
							</el-form-item>
						</el-col>
						<el-col :lg="12" style="padding-top:10px">
							<el-progress :percentage="this.progress"></el-progress>
						</el-col>
					</el-row>
					<el-form-item label="完成时间" prop="completeTime">
						<el-date-picker v-model="form.completeTime" placeholder="完成时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
					<el-form-item label="处理结果" prop="content">
						<el-input v-model="form.content" placeholder="处理结果" type="textarea" clearable maxlength="380"></el-input>
					</el-form-item>
					<el-form-item label="相关附件" prop="attachId">
						<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'task'}" :showFileList="false" @success="addNewFile">
							<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
						</sc-upload-file>
						<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
					</el-form-item>
				</el-form>
				<div style="text-align: center;">
					<el-button @click="visible=false">取 消</el-button>
					<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
				</div>
			</el-main>
		</el-container>
	</el-drawer>
</template>
<script>
import AttachMenu from '@/views/module/attachMenu'
export default {
	components: {AttachMenu},
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			apiObj: this.$API.file.attach.uploadFile,
			visible: false,
			isSaveing: false,
			fileList: [],
			progress: 1,
			//表单数据
			form: {
				taskDataId: '',
				content: '',
				progress: 0,
				templateName: "",
				completeTime: "",
				attachId: "",
			},
			//验证规则
			rules: {
				completeTime: [
					{required: true, message: '完成时间不能为空', trigger: 'blur'}
				],
				content: [
					{required: true, message: '处理结果不能为空', trigger: 'blur'}
				],
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		//表单提交方法
		submit() {
			this.form.progress= (this.progress/100);
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.clue.task.insertTaskProcess.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		addNewFile(res, file)
		{
			let tArr = this.form.attachId.split(",");
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		},
		setData(data) {
			this.form.taskDataId = data.taskDataId
			this.form.progress = data.progress
			this.progress = data.progress * 100;
		},
	}
}
</script>

<style>
</style>
